package com.example.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

//@Aspect
//@Component
public class PerformanceAspect {
    private static final Logger log = LoggerFactory.getLogger(PerformanceAspect.class);

    /** 拦截 computePlan */
    @Around("execution(* com.example.service.Compute.computePlan(..))")
    public Object aroundComputePlan(ProceedingJoinPoint pjp) throws Throwable {
        long start = System.currentTimeMillis();
        log.info(">>> ENTER computePlan, args={} ", pjp.getArgs());
        Object result = pjp.proceed();
        long took = System.currentTimeMillis() - start;
        log.info("<<< EXIT  computePlan, took={}ms", took);
        return result;
    }

    /** 拦截 execZones */
    @Around("execution(* com.example.service.Compute.execZones(..))")
    public Object aroundExecZones(ProceedingJoinPoint pjp) throws Throwable {
        long start = System.currentTimeMillis();
        log.debug(">>> ENTER execZones");
        Object result = pjp.proceed();
        long took = System.currentTimeMillis() - start;
        log.debug("<<< EXIT  execZones, took={}ms", took);
        return result;
    }

    /** 拦截 globalRefill */
    @Around("execution(* com.example.service.Compute.globalRefill(..))")
    public Object aroundGlobalRefill(ProceedingJoinPoint pjp) throws Throwable {
        long start = System.currentTimeMillis();
        log.trace(">>> ENTER globalRefill");
        Object result = pjp.proceed();
        long took = System.currentTimeMillis() - start;
        log.trace("<<< EXIT  globalRefill, took={}ms", took);
        return result;
    }
}
